<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>充值</title>
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/base.css" />
		<link rel="stylesheet" type="text/css" href="${BASE_PATH}/static/app/css/header.css"/>
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/public.css" />
		<link rel="stylesheet" href="${BASE_PATH}/static/app/css/login.css" />
		<style>
		.disable {
				background-color: #DCDCDC;
			}
		</style>
	</head>
	<body>
		<div class="header">
				<span class="back" onclick="javascript:history.go(-1);"></span>
				<a href="${BASE_PATH}/index"><span class="logo_pic"></span></a>
				<span class="logo_text">OK 妈咪</span>
				<!-- <span class="header_text">我的积分</span> -->
		</div>
		<div class="users line">
			<span>输入充值金额</span>
			<input type="text" id="samount" style="width: width: 35%;" placeholder="输入充值金额" />
		</div>
		<input type="button" style="width: 200px ;height: 35px ;background-color: #b2e2e2 ;color: white ;border-radius: 3px ;position: relative;left: 50% ;
	text-align: center;line-height: 35px;margin: 30px 0 0 -100px;border: none;" id="confirm"  onclick="paymkttransfers()" value="充值">
		
		<script type="text/javascript" src="${BASE_PATH}/static/app/js/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="${BASE_PATH}/static/lib/layer/layer.js"></script>
		<script type="text/javascript" src="${BASE_PATH}/static/app/js/kit.js"></script>
		<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script type="text/javascript">
		wx.config({appId: '${appId}',timestamp: '${timestamp}',nonceStr: '${nonceStr}',signature: '${signature}',jsApiList: ['chooseWXPay']});
		 function paymkttransfers(){
		/* 	 $("#confirm").addClass("disable").attr("disabled", "disabled"); */
		  	 var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
			 var amount = $("#samount").val();
			  if (reg.test(amount)) {
	        	  	Kit.ajax.post("${BASE_PATH}/my/paymkttransfers",{chargeNum:"${chargeNum}",amount:amount,flag:1},function(result){
	        	  		if(result.flag==0){
	    					wx.chooseWXPay({
	    						appId: '${appId}',
	    					    timestamp: result.object.timeStamp,
	    					    nonceStr: result.object.nonceStr,
	    					    package: result.object.package,
	    					    signType: result.object.signType,
	    					    paySign: result.object.paySign,
	    					    success: function (res) {
	    					    	if(res.errMsg == "chooseWXPay:ok"){
	    					    		Kit.ui.alert("支付成功",function(){
	    									turnToOrderList();	    									
	    								});
	    					    	}else if(res.errMsg == "chooseWXPay:cancel"){
	    					    		Kit.ui.alert("支付被取消！");	
	    					    		return ;
	    					    	}else if(res.errMsg == "chooseWXPay:fail"){
	    					    		var popup = '<div class="app-result-wrapper am-text-center"><i class="am-icon-close am-text-danger" style="font-size:100px;"></i><div>支付失败！</div></div><a href="javascript:turnToOrderList();" class="am-btn am-btn-danger am-btn-block am-radius app-m-t-10">关闭</a>';
	    								Kit.ui.popup(popup,"padding:10px;width:90%;");
	    					    	}
	    					    }
	    					});
	    				}else{
	    					Kit.ui.alert("支付失败！",function(){
	    						turnToOrderList();
	    					});
	    				}
					}); 
		     }else{
		    	 Kit.ui.alert("输入不规范");
		          $("#confirm").removeClass("disable").removeAttr("disabled", "disabled");
		     };
		 }
		 function turnToOrderList(){
				Kit.render.redirect("${BASE_PATH}/my/myWallet");
			}
		</script>
	</body>
</html>
